


package com.briup.web.controller;

import com.briup.DTO.AccountDTO;
import com.briup.VO.AuthGetAcountInfoVO;
import com.briup.annotation.SystemLog;
import com.briup.exception.SystemException;
import com.briup.result.Result;
import com.briup.service.AccountService;
import com.briup.util.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@CrossOrigin
@Slf4j
@Api(tags = "认证模块")
public class AuthController {
    @Autowired
    private AccountService accountService;

    @Autowired
    private RedisUtils redisUtils;

    @PostMapping("/login")
    @ApiOperation("登录接口")
    @SystemLog(business = "登录")
    public Result login(AccountDTO accountDTO) throws SystemException {
        Map<String,String> map = accountService.login(accountDTO);
        return Result.success(map);
    }

    @GetMapping("/logout")
    @ApiOperation("登出接口")
    @SystemLog(business = "登出")
    public Result logout(@RequestAttribute("id") String id)  {
        accountService.logout(id);
//        request.getSession(false).invalidate();
        return Result.success();
    }

    @GetMapping("/me")
    @ApiOperation("获取当前登录用户信息接口")
    @SystemLog(business = "获取当前登录用户信息")
    public Result me(@RequestAttribute Integer id)  {
//        log.info("id={}",id);
        AuthGetAcountInfoVO authGetAcountInfoVO= accountService.getAccounts(id);
        return Result.success(authGetAcountInfoVO);
    }
}
